{extend name="common/base" /}

{block name="style"}

{/block}
{block name="body"}
<div class="xgsjh-mains">
    <ul class="xgsjh-nav">
        <li>
            <div class="jh-nav-li">手机号</div>
            <input type="text" class="jh-nav-inp" readonly="readonly" value="{$user_info.hide_phone}" >
            <input type="hidden" class="js-phone"  value="{$user_info.phone}">
            <div class="jh-nav-y js-yzm" is_allow_click='1'>获取验证码</div>
        </li>
        <li class="li1">
            <div class="jh-nav-li">验证码</div>
            <input type="number" class="jh-nav-inp js-vcode" placeholder="请输入验证码">
        </li>          
    </ul>
    <div class="xgnc-button2">下一步</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        $('.xgnc-button2').on('click', function () {
            var vcode = $('.js-vcode').val();
            var phone = $('.js-phone').val();
            if (vcode == '') {
                $.toast('请填写验证码', "cancel");
                return;
            }
            $.post("{:url('setPhoneOne')}", {phone: phone,vcode:vcode}, function (res) {
                if (res.code == '1') {
                    location.href = "{:url('setPhoneTwo')}";
                } else {
                    mui.alert(res.msg);
                }
            }, 'json');
        });

        //发送验证码
        $('.js-yzm').click(function () {
            var phone = $('.js-phone').val();
            if (!is_mobile(phone)) {
                mui.toast('请填写正确格式手机号');
                return false;
            }
            var obj = $(this);
            if (obj.attr('is_allow_click') == 1) {
                settime($(this));
                $.post("{:url('pub/sendVcode')}", {phone: phone}, function (res) {
                    mui.toast(res.msg);
                }, 'json');
            }
        });
    });

    //验证码发送
    var countdown = 60;
    function settime(obj) { //发送验证码倒计时
        console.log(countdown);
        if (countdown == 0) {
            obj.attr('is_allow_click', 1);
//            obj.attr('disabled', false);
            //obj.removeattr("disabled"); 
            obj.text("获取验证码");
            countdown = 60;
            return;
        } else {
            obj.attr('is_allow_click', 0);
//            obj.attr('disabled', true);
            obj.text("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function () {
            settime(obj);
        }, 1000);
    }
</script>
{/block}